package com.cloud.schedule.api.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cloud.schedule.api.job.ScheduleJob;
import com.cloud.schedule.api.service.ScheduleService;
import com.cloud.schedule.common.result.Quokka;

@RestController
@RequestMapping("/schedule")
public class ScheduleController {

	@Autowired
	private ScheduleService scheduleService;

	@RequestMapping("listbygroupname")
	public Quokka listJobsByGroupName(String jobGroup) {
		return new Quokka("data", scheduleService.listJobsByGroupName(jobGroup));
	}
	
	@RequestMapping("showjobdetail")
	public Quokka showJobDetail(@RequestBody ScheduleJob job) {
		return new Quokka("data", scheduleService.showJobDetail(job));
	}
	
	@RequestMapping("pause")
	public Quokka pauseJob(@RequestBody ScheduleJob job) {
		this.scheduleService.pauseJob(job);
		return new Quokka("data", job.getJobId());
	}
	
	@RequestMapping("resume")
	public Quokka resumeJob(@RequestBody ScheduleJob job) {
		this.scheduleService.resumeJob(job);
		return new Quokka("data", job.getJobId());
	}
	
	@RequestMapping("delete")
	public Quokka deleteJob(@RequestBody ScheduleJob job) {
		this.scheduleService.deleteJob(job);
		return new Quokka("data", job.getJobId());
	}
	
	
	@RequestMapping("runonce")
	public Quokka runOnce(@RequestBody ScheduleJob job) {
		this.scheduleService.runOnce(job);
		return new Quokka("data", job.getJobId());
	}
	
	@RequestMapping("saveupdate")
	public Quokka saveUpdate(@RequestBody ScheduleJob job) {
		this.scheduleService.saveUpdate(job);
		return new Quokka("data", job.getJobId());
	}
	
	
}
